<template>
  <div>
    <input id="fileInput" type="file" @change="fileChange" />
    <img id="img" src="../assets/bg.png" alt="" />
  </div>
</template>
 
<script>
import compressImg from "../utils/compressImg";
export default {
  name: "vueName",
  data() {
    return {};
  },
  created() {
    let daysRemaining = 1;
    console.log(Math.abs(daysRemaining));
  },
  methods: {
    fileChange(e) {
      let file = e.target.files[0]; // 获取文件详情
      // 压缩图片 0.2 选填
      compressImg(file, 0.2).then((res) => {
        img.src = window.URL.createObjectURL(res.file);
      });
    },
  },
};
</script>
 
<style scoped lang = "less">
#img {
  width: 400px;
  height: auto;
}
</style>